import java.util.Stack;

public class L20 {
    public static void main(String[] args) {
        boolean valid = new Solution().isValid("([}}])");
        System.out.println(valid);
    }

    static class Solution {
        public boolean isValid(String s) {
            Stack<Character> strings = new Stack<>();
            char[] chars = s.toCharArray();
            for (int i = 0; i < chars.length; i++) {
                if (chars[i] == '{') {
                    strings.push('}');
                } else if (chars[i] == '[') {
                    strings.push(']');
                } else if (chars[i] == '(') {
                    strings.push(')');
                } else if (!strings.isEmpty() && strings.peek() == chars[i]) {
                    strings.pop();
                } else {
                    return false;
                }
            }

            return strings.isEmpty();

        }
    }
}
